package starwars.example;

import com.badlogic.gdx.math.Vector2;

public class Tracer extends Item{
	Field field=null;

	public Tracer(Field field, FixtureAtlas fAtlas, String id, int x, int y) {
		super(field, fAtlas, id, x, y);
		this.field=field;

	}

	public void onUpdate(float pSecondsElapsed) {
		final Vector2 vT=this.body.getWorldCenter();
		final Tracer tracer=this;
		
		if(field != null){
			field.forEachItem("spaceship",new CollectionHandler(){
				public void analyse(Item spaceship) {
					Vector2 vS=spaceship.body.getWorldCenter();
					Vector2 direction=vT.sub(vS);

					final float rotationInRad = (float) ((float)Math.atan2(direction.y,direction.x)+Math.PI);
					//tracer.setTransform(tracer.getWorldCenter(), rotationInRad);
					tracer.setRotation(rotationInRad);
				}
			});
		}
		
	}

	public void reset() {
	}

}
